import { defineStore } from 'pinia'
import { ElMessage } from 'element-plus'

export const useLocationStore = defineStore('location', {
    state: () => ({
      currentPosition: null,
      loading: false,
      error: null
    }),
  
    actions: {
      setPosition(position) {
        this.loading = false
        this.currentPosition = position
        this.error = null
        ElMessage.success(`定位成功: ${position.latitude}, ${position.longitude}`)
        // 触发定位成功事件
        window.dispatchEvent(new CustomEvent('location-ready'))
      },
  
      clearPosition() {
        this.currentPosition = null
        this.loading = false
        this.error = null
      }
    }
})